package com.changan.jwtdemo.controller;

import com.changan.jwtdemo.config.JwtConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TokenController {
    @Resource
    private JwtConfig jwtConfig;

    @GetMapping("/login")
    public String login(){
        String token = jwtConfig.createToken("ange");
        return token;
    }

    /**
     *
     * @param token
     * @return
     */
    @GetMapping("/getSub")
    public String getSub(String token){
        String username = jwtConfig.getUsernameFromToken(token);
        return username;
    }

    /**
     * token的目的就是要对所有能够访问的请求进行拦截
     * @param token
     * @return
     */
    @GetMapping("/getInfo")
    public String getInfo(String token){
        return "info";
    }
}
